import request from '@/utils/request'
import Qs from 'qs'
import fileRequest from '@/utils/fileRequest'

/*TODo 注意,如果是psot请求,不加params  ,get请求需要加上*/


// 登录方法   后端引入了security 需要提交方式为表单提交 使用security中的校验，此方法北废弃
export function adminLogin(username, password) {
  const data = {
    "username":username,
    "password":password
  };
  console.log("登录的账号:", username);
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    url: '/admin/login',
    method: 'post',
    data:Qs.stringify(data),
  })
}



// 用户绑定角色
export function bindRole(userId, roleIdList) {
  const data = {
    "adminId":userId,
    "roleIdList":roleIdList
  };
  return request({
    url: '/admin/bindRole',
    method: 'post',
    data
  })
}



// 获取用户详细信息
export function getCurrent() {
  return request({
    url: '/admin/getCurrent',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 分页查询
export function userPage(param) {
  let data = {
    "current":param.current,
    "size":param.size,
    "name":param.userName,
    "mobile":param.mobile,
    "email":param.email,
    "status":param.status
  };
  return request({
    url: '/admin/page',
    method: 'get',
    params:data
  })
}

/**
 * 首页数据
 * @param current
 * @param size
 */
export function infoCardData() {
  return request({
    url: '/admin/infoCardData',
    method: 'get',
  })
}


// 博客周活跃数
export function weekActive() {
  return request({
    url: '/admin/weekActive',
    method: 'get',
  })
}

// 修改密码
export function editPassword(obj) {
  let data = {
    "password":obj.password,
    "oldPassword":obj.oldPassword,
    "confirmPw":obj.confirmPw
  };
  return request({
    url: '/admin/editPassword',
    method: 'post',
    data
  })
}

// 超级管理员代激活账号
export function adminActive(id) {
  let data = {
    "id":id + '',
  };
  return request({
    url: '/admin/adminActive',
    method: 'put',
    params:data
  })
}

// 超级管理员代激活账号
export function disableAccount(id) {
  let data = {
    "id":id + '',
  };
  return request({
    url: '/admin/disableAccount',
    method: 'put',
    params:data
  })
}

// 超级管理员代激活账号
export function addAdmin(obj) {
  let data = {
    "userName":obj.userName,
    "email":obj.email,
    "mobile":obj.mobile
  };
  return request({
    url: '/admin/addAdmin',
    method: 'post',
    data
  })
}

// 导出excel
export function exportExcel(){
  let data = {
  };
  fileRequest({
    url: '/admin/exportAdmin',
    method: 'get',
    params:data,
    responseType:'blob'
  })
}


// 修改管理员信息
export function editAdmin(obj){
  let data = {
    "id":obj.id,
    "userName":obj.userName,
    "gender":obj.gender,
    "avatar":obj.avatar,
    "email":obj.email,
    "birthdayStr":obj.birthday,
    "mobile":obj.mobile,
    "summary":obj.summary,
    "nickName":obj.nickName,
    "qqNumber":obj.qqNumber,
    "weChat":obj.weChat,
    "github":obj.github,
    "gitee":obj.gitee
  };
  return request({
    url: '/admin/editAdmin',
    method: 'put',
    data,
  })
}


//查询用户未读消息列表
export function getNoReadMessageList() {
  return request({
    url: '/message/getNoReadMessageList',
    method: 'get'
  })
}
